package org.sparkle.db.company;

import org.sparkle.db.basic.BaseServiceImpl;
import org.sparkle.fs.company.CompanyFactory;
import org.sparkle.ioc.Bean;

import com.avaje.ebean.Ebean;

@Bean("company-service")
public class CompanyServiceImpl extends BaseServiceImpl<CompanyVO> implements CompanyService {

	public CompanyServiceImpl() {
		super(CompanyVO.class);
	}

	@Override
	public CompanyVO getByName(String name) {
		return Ebean.find(CompanyVO.class).where().eq("name", name).findUnique();		
	}
		
	@Override
	public void saveAndCreateStructure(CompanyVO vo) throws Exception {
		try{
			super.save(vo);
		}catch(Exception e){
			throw e;
		}
		
		CompanyFactory.getInstance().createStructure(vo);
	
	}

}
